package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/25.
 */

public class triangleView2 extends BaseView {

    public triangleView2(Context context) {
        super(context);
        init();
    }

    public triangleView2(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    int widht = ProportionUtils.getInstance().adapterInt(670);
    int height = ProportionUtils.getInstance().adapterInt(160);

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(widht, height);
    }

    private void init() {
    }

    String index = "1";
    String info = "设施环境标准";

    public void setIndexAndInfo(String index, String info) {
        this.index = index;
        this.info = info;
        invalidate();
    }

    int w = ProportionUtils.getInstance().adapterInt(82);
    int textSize = ProportionUtils.getInstance().adapterInt(38);

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        canvas.drawColor(Color.WHITE);
        Path path = new Path();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setStrokeWidth(0);
        path.moveTo(0, 0);
        path.lineTo(w, 0);
        path.lineTo(0, w);
        path.close();
        paint.setColor(Color.parseColor("#4B97F0"));
        canvas.drawPath(path, paint);
        paint.setColor(Color.WHITE);
        paint.setTextSize(textSize);
        paint.setTextAlign(Paint.Align.LEFT);
        int x = w / 5;
        int y = (int) (w - textSize * 1.15);
        canvas.drawText(index, x, y, paint);
        paint.setColor(Color.BLACK);
        paint.setTextAlign(Paint.Align.LEFT);
        //int tw= (int) paint.measureText(info,0,info.length());
        //Log.e("test","宽度:\t"+getWidth()+"\t字符串宽度:\t"+tw);
        //canvas.drawText(info, (getWidth()-tw) / 2, (getHeight() - textSize) / 2 + textSize * 0.8f, paint);
        canvas.drawText(info, getWidth()/3.5f, (getHeight() - textSize) / 2 + textSize * 0.8f, paint);
    }
}
